<?PHP
	//written by Cyanogen, Slyferz
	//just the login form

function antispam(){
    global $_SERVER;

    $t = time();
    $lockout = 300; // seconds (300 = 5 minutes)
    $ip = mysql_escape_string($_SERVER['REMOTE_ADDR']);

    // clear old entries
    mysql_query("DELETE FROM antispam WHERE date < ".($t - $lockout).";");

    // disallow if abused
    $result = mysql_query("SELECT date, attempts FROM antispam WHERE ip = '$ip';");
	$host = mysql_fetch_array($result);
    if(!empty($host)){
        $host[1] += 1;
        mysql_query("UPDATE antispam SET attempts = $host[1] WHERE ip = '$ip';");
        if($host[1] > 3){
            $seconds = $host[0] - $t + $lockout;
            $error = "Please try again in ";
            if($seconds > 3600){
                $hours = floor($seconds / 3600); $seconds -= $hours * 3600;
                $minutes = floor($seconds / 60); $seconds -= $minutes * 60;
                $error .= "$hours hours $minutes minutes $seconds seconds";
            } else if($seconds > 60){
                $minutes = floor($seconds / 60); $seconds -= $minutes * 60;
                $error .= "$minutes minutes $seconds seconds";
            } else $error .= "$seconds seconds";
            return $error;
        }
    } else {
        // add to database
        mysql_query("INSERT INTO antispam VALUES ('$ip', 1, $t);");
    }
    return "";
}

	$error = antispam();
	if(!empty($error)) echo $error;
	else
	{
		echo("	
			<form name='login' action='index2.php?page=error' method='post'>
			<table class = 'middle'>
				<!--Logging user on-->
				<tr>
					<td>UserID:</td><td><input class = 'input-box' type='text' maxlength = '24' name='uname' size = '10' /></td>
				</tr>
				<tr>
					<td>Password:</td><td><input class = 'input-box' type='password' maxlength = '24' name='pass' size = '10' /></td>
				</tr>
			</table>
			<p>
				<input type='submit' value='Login' />
			</p>
			</form>");
	}
?>
